package com.kotlin.hxh.ui.fragment.second.child

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.kotlin.hxh.R
import com.kotlin.hxh.base.BaseBackFragment
import com.kotlin.hxh.ui.fragment.CycleFragment
import kotlinx.android.synthetic.main.fragment_modify_detail.*
import kotlinx.android.synthetic.main.toolbar.*

/**
 * @author huxh
 * @date 2018/12/19.
 */
class ModifyDetailFragment : BaseBackFragment() {

    private var mTitle: String? = null

    companion object {
        private val ARG_TITLE = "arg_title"
        @JvmStatic
        fun newInstance(title: String?): ModifyDetailFragment {
            val args = Bundle()
            val fragment = ModifyDetailFragment()
            args.putString(ARG_TITLE, title)
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mTitle = arguments?.getString(ARG_TITLE)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) = inflater.inflate(R.layout.fragment_modify_detail, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView(view)
    }

    private fun initView(view: View) {
        toolbar.setTitle(R.string.start_result_test)
        initToolbarNav(toolbar)

        et_modify_title.setText(mTitle)

        // 显示 软键盘
        //        showSoftInput(mEtModiyTitle);

        btn_next.setOnClickListener {
            val bundle = Bundle()
            bundle.putString(DetailFragment.KEY_RESULT_TITLE, et_modify_title.text.toString())
            setFragmentResult(ISupportFragment.RESULT_OK, bundle)

            Toast.makeText(_mActivity, R.string.modify_success, Toast.LENGTH_SHORT).show()
        }
        btn_next.setOnClickListener(View.OnClickListener { start(CycleFragment.newInstance(1)) })
    }

    override fun onSupportInvisible() {
        super.onSupportInvisible()
        hideSoftInput()
    }
}